
import axios from 'axios';

class ESync {
  constructor() {
    this.userId = 0;
    this.token = "";
    this.repoId = 0;
    this.axios = axios.create({
      baseURL: "http://127.0.0.1:18083",
      timeout: 5 * 1000,
    });
  }

  setToken(userId, token) {
    this.userId = userId;
    this.token = token;
    this.axios.defaults.headers.common['Authorization'] = `USER ${userId} ${token}`;
  }

  Login(userName, pwd, remember) {
    let form = {
      user_name: userName,
      password: pwd,
      remember: remember,
    }
    return this.axios.post("/api/v1/user/login", form);
  }

  getServerInfo() {
    return this.axios.get('/api/v1/server/');
  }

  fetchDeviceInfo(form) {
    return this.axios.put('/api/v1/server/device', form);
  }

  getDeviceList() {
    return this.axios.get('/api/v1/dcim/devices/');
  }

  getServerDiskInfo() {
    return this.axios.get('/api/v1/dcim/disk/info');
  }

  getAlbumLists() {
    return this.axios.get('/api/v1/dcim/albums/');
  }

  getFileLists(albumID) {
    return this.axios.get(`/api/v1/dcim/albums/${albumID}/files`);
  }

  fetchAlbumInfo(form) {
    return this.axios.put('/api/v1/dcim/albums/', form);
  }

  getAlbumInfo(albumID) {
    return this.axios.get(`/api/v1/dcim/albums/${albumID}/`);
  }

  quickUpload(albumID, form) {
    return this.axios.put(`/api/v1/dcim/albums/${albumID}/upload/quick`, form);
  }

  fullUpload(albumID, form) {
    return this.axios.put(`/api/v1/dcim/albums/${albumID}/upload/full/picture`, form);
  }

  removeFile(fileID) {
    return this.axios.delete(`/api/v1/dcim/files/${fileID}/`);
  }

  getRawFile(fileID) {
    return this.axios.get(`/api/v1/dcim/files/${fileID}/raw`);
  }
}

export default new ESync();
